package com.dk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dk.model.Shop;
import com.dk.mapper.ShopMapper;
import com.dk.service.ShopService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dk.vo.ShopVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author wbh
 * @since 2023-03-21
 */
@Service
public class ShopServiceImpl extends ServiceImpl<ShopMapper, Shop> implements ShopService {
    @Resource
    private ShopMapper shopMapper;

    @Override
    public List<ShopVO> getInfoList(ShopVO shopVO) {
        /* 车间编码,车间名称*/
        LambdaQueryWrapper<Shop> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(StringUtils.isNotBlank(shopVO.getShopCode()),Shop::getShopCode,shopVO.getShopCode());
        wrapper.like(StringUtils.isNotBlank(shopVO.getShopName()),Shop::getShopName,shopVO.getShopName());
        List<ShopVO> collect = shopMapper.selectList(wrapper).stream().map(shop -> {
            ShopVO shopVO1 = new ShopVO();
            BeanUtils.copyProperties(shop, shopVO1);
            return shopVO1;
        }).collect(Collectors.toList());
        return collect;
    }

    @Override
    public void insertInfoShop(ShopVO shopVO) {
        Shop shop = new Shop();
        BeanUtils.copyProperties(shopVO,shop);
        shopMapper.insert(shop);
    }

    @Override
    public ShopVO getInfoShopById(String shopCode) {
        Shop shop = shopMapper.selectById(shopCode);
        ShopVO vo = new ShopVO();
        BeanUtils.copyProperties(shop,vo);
        return vo;
    }

    @Override
    public void updateInfoShopById(ShopVO shopVO) {
        Shop shop = new Shop();
        BeanUtils.copyProperties(shopVO,shop);
        shopMapper.updateById(shop);
    }

    @Override
    public void deleteInfoShopById(String shopCode) {
        shopMapper.deleteById(shopCode);
    }
}
